package com.hzjh.base.ext.http

import android.os.Build
import com.blankj.utilcode.util.AppUtils
import com.blankj.utilcode.util.NetworkUtils
import com.hzjh.base.ext.data.UserConfigs
import com.hzjh.base.http.interceptor.TokenInterceptor
import com.hzjh.base.utils.other.ActivityStackManage
import okhttp3.Headers
import java.util.Locale

class HttpConfig {
    companion object{
        val SignKey = "zjjh@yyds2024"
        fun init() {
            addHeaders()
        }

        fun addHeaders(sign:String?=null){
            TokenInterceptor.setHeaders{
                Headers.Builder().apply {
                    if(UserConfigs.isLogin()){
                        add("Authori-zation", UserConfigs.getUserData().token?:"")
                    }
                    add("version-num", "${AppUtils.getAppVersionCode()}")
                    add("version-str", AppUtils.getAppVersionName())
                    add("c-type", "android")
                    add("oaid", UserConfigs.oaid)
                    add("model", Build.MODEL)
                    add("device", Build.DEVICE)
                    add("brand", Build.BRAND)
                    add("network-type", NetworkUtils.getNetworkType().name)
                    add("country",Locale.getDefault().country)
                    add("referer-page",ActivityStackManage.currentActivity()?.javaClass?.canonicalName?:"")
                    sign?.let {
                        add("sign", it)
                    }
                }.build()
            }
        }
    }
}